<?php

ini_set('max_execution_time', 999999999);
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("player_profile", $con);

$teams = array(
"/(Arizona Cardinals)/",
"/(Phoenix Cardinals)/",
"/(St. Louis Cardinals)/",
"/(Chicago Cardinals)/",
"/(Atlanta Falcons)/",
"/(Baltimore Ravens)/",
"/(Buffalo Bills)/",
"/(Carolina Panthers)/",
"/(Chicago Bears)/",
"/(Chicago Stanleys)/",
"/(Decatur Stanleys)/",
"/(Cincinnati Bengals)/",
"/(Cleveland Browns)/",
"/(Dallas Cowboys)/",
"/(Denver Broncos)/",
"/(Detroit Lions)/",
"/(Portsmouth Spartans)/",
"/(Green Bay Packers)/",
"/(Houston Texans)/",
"/(Indianapolis Colts)/",
"/(Baltimore Colts)/",
"/(Jacksonville Jaguars)/",
"/(Kansas City Chiefs)/",
"/(Miami Dolphins)/",
"/(Minnesota Vikings)/",
"/(New England Patriots)/",
"/(Boston Patriots)/",
"/(New Orleans Saints)/",
"/(New York Giants)/",
"/(New York Jets)/",
"/(New York Titans)/",
"/(Oakland Raiders)/",
"/(Los Angeles Raiders)/",
"/(Oakland Raiders)/",
"/(Philadelphia Eagles)/",
"/(Pittsburgh Steelers)/",
"/(Pittsburgh Pirates)/",
"/(San Diego Chargers)/",
"/(Los Angeles Chargers)/",
"/(San Francisco 49ers)/",
"/(Seattle Seahawks)/",
"/(St. Louis Rams)/",
"/(Los Angeles Rams)/",
"/(Cleveland Rams)/",
"/(Tampa Bay Buccaneers)/",
"/(Tennessee Titans)/",
"/(Tennessee Oilers)/",
"/(Houston Oilers)/",
"/(Washington Redskins)/",
"/(Boston Redskins)/",
"/(Boston Braves)/");
$replacements = array();
foreach($teams as $team){
	$replacements[] = ",$1,";
}

$select = "Select * from players where team is not null";

$result = mysql_query($select);
$count = 0;
echo var_dump($teams);
echo var_dump($replacements);
while($r = mysql_fetch_assoc($result)){
	$team = $r['team'];
	echo "before:$team<br>";
	if(preg_match("/,/", $team)){
		continue;
	}
	$team = preg_replace($teams, $replacements, $team);
	$team = preg_replace("/, ,/", ",", $team);
	$team = preg_replace("/^,/", "", $team);
	$team = preg_replace("/,$/", "", $team);
	echo "after:$team<br>";
	$id = $r['id'];
	$update = "UPDATE players set team = '$team' where id=$id";
	echo "update: $update<br>";
	mysql_query($update);
	$count++;
}
echo "Updated $count errors";

?>